import 'package:flutter/material.dart';


import 'child_widget.dart';
import 'share_data_widget.dart';


class InheritedDemo extends StatefulWidget {
  @override
  _InheritedDemoState createState() => _InheritedDemoState();
}

class _InheritedDemoState extends State<InheritedDemo> {
  int _count = 0;
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Padding(
            padding: const EdgeInsets.only(bottom: 20.0),
            child: ShareDataWidget(
              //使用ShareDataWidget
              data: _count,
              child: ChildWidget1(), //子widget中依赖ShareDataWidget
            ),
          ),
          RaisedButton(
            child: const Text('Increment'),
            //每点击一次，将count自增，然后重新build,ShareDataWidget的data将被更新
            onPressed: () => setState(() => ++_count),
          )
        ],
      ),
    );
  }
}
